package net.tv90.bfmccore.listener;

import net.tv90.bfmccore.battlepass.Battlepass;
import net.tv90.bfmccore.constant.RewardConstant;
import org.bitterorange.flansmodslain.actions.Money;
import org.bitterorange.flansmodslain.actions.Point;
import org.bitterorange.flansmodslain.models.BukkitVehicleDamageEvent;
import org.bitterorange.flansmodslain.models.BukkitVehicleDestroyEvent;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;

public class AntiVehicleListener implements Listener {

    @EventHandler
    public void vehicleDestroyEvent(BukkitVehicleDestroyEvent e) {
        Player p = e.getAttacker();
        double totalMoneyAdded = 40 * RewardConstant.MONEY_MAGNIFICATION;
        int totalPointsAdded = 20 * RewardConstant.RANK_MAGNIFICATION;
        Money.give(p, totalMoneyAdded);
        Point.add(p, totalPointsAdded);
        Battlepass.addBattlepassPoint(p, (int) (400 * RewardConstant.POINT_MAGNIFICATION));
        p.sendMessage("§e[击毁载具]你击毁了" + e.getVehicleName() + "，获得" + totalMoneyAdded + "游戏币和" + totalPointsAdded + "军衔");
    }

    @EventHandler
    public void vehicleDamageEvent(BukkitVehicleDamageEvent e) {
        Player p = e.getAttacker();
        float ratio = e.getDamage() / e.getMaxDamage();
        if (ratio >= 0.3) {
            if(ratio > 1) ratio = 1;
            double totalMoneyAdded = (int) (ratio * 10 * RewardConstant.MONEY_MAGNIFICATION);
            int totalPointsAdded = (int) (ratio * 10 * RewardConstant.RANK_MAGNIFICATION);
            Money.give(p, totalMoneyAdded);
            Point.add(p, totalPointsAdded);
            Battlepass.addBattlepassPoint(p, (int) (ratio * 100 * RewardConstant.POINT_MAGNIFICATION));
            p.sendMessage("§e[重创载具]你重创了" + e.getVehicleName() + "的" + (int) (ratio * 100) + "%血量，获得" + totalMoneyAdded + "游戏币和" + totalPointsAdded + "军衔");
        }
    }
}
